﻿uint8_t SIM_Filter_Data(char *SIM_Data, char *Fil_Data, char *element)
{
	uint8_t F_e = 0, S_e = 0, result = 0;
	memset(Fil_Data, 0, 200);
	F_e = strstr(SIM_Data, element) - SIM_Data;				//获得元素的位置；
	F_e = strchr(SIM_Data+ F_e+1, ',') - SIM_Data;			//获得元素内容长度的分隔符‘，’；//+1是防止检索到自己
	S_e = strstr(SIM_Data + F_e + 1, "\r\n") - SIM_Data;	//获得元素内容长度的分隔符“回车”；//+1是防止检索到自己
	strncpy(Fil_Data, SIM_Data + F_e + 1, S_e - F_e -1);	//得到内容长度（ASCII码）；//+1是因为F_e是‘，’的位置
	result = atoi(Fil_Data);								//ASCII码内容长度->int
	///************************************************************/
	strncpy(Fil_Data, SIM_Data + S_e + 2, result);			//将原始数据从元素结尾回车开始后面n个字符提取出来
	printf("	Filter_Data =%s	", Fil_Data);
	return 0;
}
uint8_t SIM_Data(char *SIM_Data, char *Fil_Data, char *element)
{
	uint8_t F_e = 0, S_e = 0, result = 0;
	memset(Fil_Data, 0, 200);
	F_e = strstr(SIM_Data, element) - SIM_Data;				//获得元素的位置；
	S_e = strstr(SIM_Data + F_e + 1, "\r\n") - SIM_Data;	// 获得元素内容结尾“回车”；//+1是防止检索到自己
	strncpy(Fil_Data, SIM_Data + F_e + strlen(element), S_e - F_e - strlen(element));	//将原始数据（元素位置+元素长度）开始
	printf("	Filter_Data = %s	\r\n", Fil_Data);									//往后复制n个字符
	return 0;
}

int main(void)
{
	uint8_t x = 0;
	char * test = "+CMQTTRXSTART: 0,9,6\r\n+CMQTTRXTOPIC: 0,9\r\nttttttttt\r\n+CMQTTRXPAYLOAD: 0,6\r\nyyyyyy\r\n+CMQTTRXEND: 0";
	char *table = "abc:1234564\r\nbcd:12345646543\r\nasdha:45454545452454\r\nasasd:15245454\r\n";
	char FilBuf[200] = "\0";
	SIM_Data(table, FilBuf, "asdha:");
	SIM_Filter_Data(test, FilBuf, "+CMQTTRXPAYLOAD:");
	system("pause");
	return 0;
}

/////////////////////////////////////////
	char* out = "{\"code\":0,\"msg\":\"channel\",\"data\":[{\"goodsId\":2,\"count\":2,\"cargoNo\":1},{\"goodsId\":5,\"count\":3,\"cargoNo\":2}]}";


	cJSON *json = cJSON_Parse(out);
	cJSON *json_code = cJSON_GetObjectItem(json, "code");
	cJSON *json_msg = cJSON_GetObjectItem(json, "msg");
	cJSON *json_data = cJSON_GetObjectItem(json, "data");
	int arr_size = cJSON_GetArraySize(json_data);
	cJSON *arr_item = json_data->child;
	for (int i = 0; i < arr_size; i++)
	{
		cJSON *json_goodsId = cJSON_GetObjectItem(arr_item, "goodsId");
		cJSON *json_count = cJSON_GetObjectItem(arr_item, "count");
		cJSON *json_cargoNo = cJSON_GetObjectItem(arr_item, "cargoNo");
		arr_item = arr_item->next;
		printf("json_goodsId:%d, json_count : %d, json_cargoNo : %d\n", json_goodsId->valueint, json_count->valueint, json_cargoNo->valueint);
	}
	
	printf("name:%d, msg : %s, data : %s\n", json_code->valueint, json_msg->valuestring, json_data->valuestring);
	cJSON_Delete(json);
	cJSON_Delete(arr_item);





